home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / AmigaBasicProgs / Cload < prev    next >
Text File  |  1986-04-01  |  3KB  |  116 lines

  1. '  cload
  2. '
  3. '  adopted from cload.c, which was written by Bill Bolton 76244,127
  4. '    sysop of the Software Tools RCPM   Kenmore, Australia
  5. '  Amigabasic implementation by Richard Webb 74005,1265
  6. '
  7. '  syntax:  the program is run from Amigabasic, and will prompt for the
  8. '           input and output file names
  9. '
  10. '  input:   an ascii file in either of the two hex formats used by CIS,
  11. '           checksum and no checksum -- the program recognizes which
  12. '           type is being used
  13. '
  14. '  output:  a binary image of the file as it was originally uploaded to CIS
  15. '
  16. '  bugs:    - if a character is missing from a hex line (as from a phone
  17. '             line dropout), the program quits with the error message
  18. '             "Illegal function call" when it tries to "ASC" a null string;
  19. '             the action is proper but not very informative
  20. '           - it's SLOOWWWW -- but hopefully, you'll only need it once, to
  21. '             get an Xmodem terminal program up and running.
  22. '
  23. '  version 1.0, 19 Jan 86
  24.  
  25. version$ = "1"
  26. revision$ = "0"
  27. working% = 10                    ' number of lines between progress reports
  28. next.line% = working% * 32       ' number of progress chars/screen line
  29.  
  30.  
  31. PRINT "Hex to binary converter for CIS downloads, ";version$;".";revision$
  32. INPUT "Name of hex file to convert:  ",in.file$
  33. INPUT "  Binary file to be created:  ",out.file$
  34. PRINT
  35.  
  36. CALL convert(in.file$, out.file$)
  37.  
  38. END
  39.  
  40.  
  41.  
  42. SUB convert(hex.file$, bin.file$) STATIC
  43. SHARED working%, next.line%
  44.  
  45. OPEN hex.file$ FOR INPUT AS #1 LEN = 10240
  46. OPEN bin.file$ FOR OUTPUT AS #2 LEN = 10240
  47.  
  48. line.count% = 0
  49. line.length% = -1    ' forces one trip thru the WHILE loop (no DO-WHILE!)
  50.  
  51. WHILE (line.length% <> 0)
  52.   line.count% = line.count% + 1
  53.   IF line.count% MOD working% = 0 THEN
  54.     PRINT "*";    ' still alive
  55.     IF line.count% MOD next.line% = 0 THEN
  56.       PRINT
  57.     END IF
  58.   END IF
  59.  
  60.   INPUT #1, input.line$
  61.   IF EOF(1) THEN
  62.     CLOSE #1 : CLOSE #2
  63.     PRINT : PRINT "Conversion completed " : BEEP
  64.     END
  65.   END IF
  66.  
  67.   in.string.pos% = 2                ' skip over leading colon
  68.   CALL read.hex(line.length%,2,in.string.pos%,input.line$)
  69.                                     ' get number of chars in this line
  70.   FOR i% = 1 TO 3
  71.     CALL read.hex(address%,2,in.string.pos%,input.line$)
  72.     sum% = sum% + address%          ' add address to chechsum
  73.   NEXT i%
  74.  
  75.   FOR i% = 1 TO line.length%          ' where the rubber meets the road
  76.     CALL read.hex(char%,2,in.string.pos%,input.line$)
  77.     char$ = CHR$(char%)
  78.     PRINT #2, char$;
  79.     sum% = sum% + char%
  80.   NEXT i%
  81.  
  82. ' end of line processing
  83.   IF LEN(input.line$) > 2 * line.length% + 9 THEN     ' meaning room for
  84.     CALL read.hex(char%,2,in.string.pos%,input.line$) ' the checksum byte
  85.     sum% = ( (sum% + char% + line.length%) AND &HFF)  ' so this is the
  86.     IF sum% <> 0 THEN                                 ' hex format with
  87.       PRINT                                           ' checksums
  88.       PRINT "Checksum error on line ";line.count%
  89.       BEEP
  90.     END IF
  91.   END IF
  92.  
  93. WEND
  94.  
  95. END SUB
  96.  
  97.  
  98.  
  99. SUB read.hex(c%,qty%,posit%,in.line$) STATIC
  100.  
  101. partial% = 0
  102. FOR i% = 1 TO qty%
  103.   partial% = partial% * 16
  104.   in.str$ = MID$(in.line$,posit%,1)
  105.   posit% = posit% + 1
  106.   in.val% = ASC(in.str$)
  107.   IF in.val% < 58 THEN
  108.     partial% = partial% + in.val% - 48
  109.   ELSE
  110.     partial% = partial% + in.val% - 55
  111.   END IF
  112. NEXT i%
  113. c% = partial%
  114.  
  115. END SUB
  116.